﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace StarLabel.label.item
{
    /// <summary>
    /// Copyright 2019  ZhengJi. All Rights Reserved.
    /// 实现按指定分隔符拆分档案号
    /// </summary>
    [Obsolete ("ArchNoItem 过期,使用 SplitByCharItem")]
    public class ArchNoItem : TextItem
    {
        public char SplitChar { get; set; }
        public float OffsetY { get; set; } 

        /// <summary>
        /// 是否打印分隔符
        /// </summary>
        public string PrintSplitChar { get; set; }
        public ArchNoItem(XmlElement el) : base(el)
        {
        }
        protected override void parseFromXml()
        {
            this.OffsetY = this.xmlEl.Attributes["OffsetY"] == null ? 50:float.Parse( this.xmlEl.Attributes["OffsetY"].Value);

            this.PrintSplitChar = this.xmlEl.Attributes["PrintSplitChar"] == null ? "1" : this.xmlEl.Attributes["PrintSplitChar"].Value;

            string str= this.xmlEl.Attributes["SplitChar"] == null ? "-" :  this.xmlEl.Attributes["SplitChar"].Value;

            this.SplitChar = str[0];

            base.parseFromXml();
        }
        public override void DrawLabel(float x, float y, string labelText, string rotation)
        {
            
            string[] strArr = labelText.Split(this.SplitChar);
            string ro=this.Rotation;

            for (int i= strArr.Length-1; i>=0;i-- )
            {
               // this.Rotation = ro;

                base.DrawLabel(x, y, strArr[i],this.Rotation);
                y = y - float.Parse(this.FontHeight)- OffsetY;
                if (this.PrintSplitChar.Equals("1"))
                {
                    if (i >0 )
                    {
                        float fr = float.Parse(ro) + 90;
                       // this.Rotation = fr.ToString();
                        base.DrawLabel(x, y, this.SplitChar.ToString(),fr.ToString());
                       // y = y + OffsetY+30;
                    }
                }
                
            }
            
        }
    }
}
